﻿using BizModels;
using DataModel;
using IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Repositories
{
    public class Web2048Repository : RepositoryBase, IWeb2048Repository
    {
        public Web2048Repository()
        {
            Context = new HinokyEntities();
        }

        public bool InsertScore(Web2048ScoreT web2048ScoreT)
        {
            var data = new Game2048Ranking
            {
                Name = web2048ScoreT.Name,
                Score = web2048ScoreT.Score,
                InsertDate = DateTime.Now,
                IPAddress = web2048ScoreT.IPAddress,
            };

            Context.Game2048Ranking.Add(data);
            var result = Context.SaveChanges();

            return result > 0 ? true : false;
        }

        public List<Web2048ScoreT> GetScoreList()
        {
            var dataList = Context.Game2048Ranking.Select(s => new Web2048ScoreT
            {
                Idx = s.Idx,
                Name = s.Name,
                Score = s.Score,
                InsertDate = s.InsertDate,
                IPAddress = s.IPAddress,

            }).OrderByDescending(s => s.Score).ThenBy(s => s.InsertDate).Take(20).ToList();

            return dataList;
        }
    }
}
